<?php
/**
 * FlickrPhotosetsCanvas class file
 * @package FlickrPhotosets
 */

/**
 * Include styles.
 */
require_once 'styles.php';

/**
 * This class is responsible for displaying canvas pages.
 * 
 * It should be used to control all canvas pages unless something special
 * is required for that page.
 * 
 * @package FlickrPhotosets
 * @author Brad Dougherty <bdougherty@gmail.com>
 * @version 7.10.7
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License 3.0
 * @since Class available since Release 2.0
 */
class FlickrPhotosetsCanvas extends FlickrPhotosets {
	
	/**
	 * FBML to print at the end of the page
	 * @var string
	 */
	public $closing_fbml;
	
	/**
	 * FBML to print at the beginning of the page
	 * @var string
	 */
	public $opening_fbml;
	
	/**
	 * The current page
	 * @var int
	 */
	public $page;
	
	// For getting the uid
	const require_add = 'add';
	const require_login = 'login';
	const uid_from_url = 'url';
	const uid_from_viewer = 'viewer';
	
	/**
	 * Requires that the page is rendered in the frame. Get's the UID by either
	 * using the url, requiring login, requiring add, or from the viewer. It
	 * will also set up the Flickr object. $check_preferences should be set to
	 * false if the page is a "backend" page.
	 * 
	 * @author Brad Dougherty <bdougherty@gmail.com>
	 * @param string $where_uid Where to get the UID from (use static variables in FlickrPhotosets)
	 * @param boolean $initialize_flickr Initialize Flickr
	 * @param boolean $check_preferences Check that preferences are honored
	 */
	public function __construct($where_uid = 'url', $initialize_flickr = true, $check_preferences = true, $get_info = true) {
		parent::__construct();
		
		// To make this a canvas page, we should require the frame
		$this->facebook->require_frame();
		
		// Get the UID
		if ($where_uid == self::require_add) {
			$this->uid = $this->facebook->require_add();
		}
		else if ($where_uid == self::require_login) {
			$this->uid = $this->facebook->require_login();
		}
		else if ($where_uid == self::uid_from_viewer) {
			$this->uid = $this->facebook->user;
			return;
		}
		else {
			$this->uid = (!empty($_GET['uid'])) ? $_GET['uid'] : $_GET['id']; // Get the id for backwards compatibility
		}
		
		// Now that we have the UID, let's get their configuration data
		if ($get_info and !$this->get_info()) {
			$this->error(FlickrPhotosetsErrors::$not_added);
		}
		
		// Migrate to new flickr api key
		$this->_migrate_flickr_key();
				
		// Check the preferences for things that are disabled
		if ($check_preferences) {
			$this->check_preferences();
		}
		
		// Set up Flickr
		if ($initialize_flickr) {
			$this->init_flickr();
			
			// Retrieve the page number
			$this->get_page();
		}
		
		// Echo any opening fbml
		echo $this->opening_fbml;
	}
	
	/**
	 * Adds code to the opening and closing FBML to be printed before and after
	 * the content of the page. Must be called before the end of the constructor.
	 * 
	 * @author Brad Dougherty <bdougherty@gmail.com>
	 * @param string $opening_fbml The code to add to the opening FBML
	 * @param string $closing_fbml The code to add to the closing FBML
	 */
	private function add_to_fbml($opening_fbml, $closing_fbml) {
		$this->opening_fbml = $opening_fbml.$this->opening_fbml;
		$this->closing_fbml = $this->closing_fbml.$closing_fbml;
	}
	
	/**
	 * Enforces the user's preferences.
	 * 
	 * @author Brad Dougherty <bdougherty@gmail.com>
	 */
	private function check_preferences($first = true) {
		
		// If the user has disabled the gallery
		if (!$this->config['enable_gallery']) {
			// Try to redirect to the page on Flickr
			if (!empty($_GET['pid']) and !empty($_GET['sid'])) {
				$this->facebook->redirect('http://flickr.com/photos/'.$this->config['flickr_nsid'].'/'.$_GET['pid'].'/in/set-'.$_GET['sid'].'/');
			}
			else if (!empty($_GET['pid'])) {
				$this->facebook->redirect('http://flickr.com/photos/'.$this->config['flickr_nsid'].'/'.$_GET['pid'].'/');
			}
			else if (!empty($_GET['sid'])) {
				$this->facebook->redirect('http://flickr.com/photos/'.$this->config['flickr_nsid'].'/sets/'.$_GET['sid'].'/');
			}
			
			// Otherwise show an error
			$this->error(FlickrPhotosetsErrors::$gallery_disabled);
		}
		
		// If the user wants the page only visible to friends
		if ($this->config['privacy_visibility'] == $this->privacy_visibility['friends']) {
			$this->add_to_fbml(
				'<fb:if-is-friends-with-viewer uid="'.$this->uid.'">',
				'<fb:else>'.$this->error(FlickrPhotosetsErrors::$not_friends, true).'</fb:else></fb:if-is-friends-with-viewer>'
			);
		}
		
		// If the user wants to block limited profile friends
		if ($this->config['privacy_visibility'] == $this->privacy_visibility['non-limited']) {
			$this->add_to_fbml(
				'<fb:if-can-see uid="'.$this->uid.'" what="not_limited">',
				'<fb:else>'.$this->error(FlickrPhotosetsErrors::$private, true).'</fb:else></fb:if-can-see>'
			);
		}
		
	}
	
	/**
	 * Prints out the footer, which consists of the closing fbml,
	 * the disclaimer, and google analytics.
	 * 
	 * @author Brad Dougherty <bdougherty@gmail.com>
	 * @param boolean $border Whether or not to render a border
	 */
	public function echo_footer($border = false) {
		echo $this->closing_fbml;
		echo $this->print_disclaimer($border);
		echo $this->print_analytics();
	}
	
	/**
	 * Prints out a question/answer block.
	 * 
	 * @author Brad Dougherty <bdougherty@gmail.com>
	 * @param string $question The question
	 * @param string $answer The answer
	 */
	public function echo_help_item($question, $answer) {
		static $help_id = 1;
		echo '
			<div class="question">
				<a href="#" clicktotoggle="ans_'.$help_id.'">'.$question.'</a>
			</div>
			<div class="answer" id="ans_'.$help_id.'" class="answer" style="display:none;">
				'.$answer.'
			</div>
		';
		$help_id++;
	}
	
	/**
	 * Prints out the code for the tabs on the photostream, photosets,
	 * and geotagged pages. Won't show a tab if the user has disabled
	 * that portion of the application.
	 * 
	 * @author Brad Dougherty <bdougherty@gmail.com>
	 * @param string $page_name The name of the page (to set as selected)
	 */
	public function echo_tabs($page_name) {
		echo '<fb:tabs>';
		if ($this->config['enable_gallery_photostream']) {
			echo '<fb:tab_item href="'.$this->app_url.'/photos/'.$this->uid.'/" title="Photostream"';
			if (strtolower($page_name) == 'photostream') {
				echo ' selected="true"';
			}
			echo ' />';
		}
		if ($this->config['enable_gallery_photosets']) {
			echo '<fb:tab_item href="'.$this->app_url.'/photos/'.$this->uid.'/sets/" title="Photosets"';
			if (strtolower($page_name) == 'photosets') {
				echo ' selected="true"';
			}
			echo ' />';
		}
		if ($this->config['enable_gallery_geotagged']) {
			echo '<fb:tab_item href="'.$this->app_url.'/photos/'.$this->uid.'/geo/" title="Geotagged"';
			if (strtolower($page_name) == 'geotagged') {
				echo ' selected="true"';
			}
			echo ' />';
		}
		echo '</fb:tabs>';
	}
	
	/**
	 * Attempts to match Flickr contacts to Facebook friends.
	 * 
	 * @author Brad Dougherty <bdougherty@gmail.com>
	 * @return array An array of the UIDs of Facebook friends that are potential matches
	 */
	public function find_friends_on_flickr($loose = false) {
		
		// Get the Flickr contacts and Facebook friends
		$this->flickr->setToken($this->config['flickr_token']);
		$flickr_contacts = $this->flickr->contacts_getList();
		$facebook_friend_uids = $this->facebook->api_client->friends_get();

		// Get the name of your Flickr contacts
		$flickr_friend_names = array();
		foreach ($flickr_contacts['contact'] as $friend) {
			if (!empty($friend['realname'])) {
				array_push($flickr_friend_names, $friend['realname']);
			}
		}

		// Get the names of your Facebook friends
		$facebook_friend_names = $this->facebook->api_client->users_getInfo($facebook_friend_uids, array('name', 'first_name', 'last_name'));
		for ($i = 0; $i < count($facebook_friend_names); $i++) {
			$facebook_friend_names[$i]['name_lower'] = strtolower($facebook_friend_names[$i]['name']);
			$facebook_friend_names[$i]['first_name_lower'] = strtolower($facebook_friend_names[$i]['first_name']);
			$facebook_friend_names[$i]['last_name_lower'] = strtolower($facebook_friend_names[$i]['last_name']);
		}

		/*
		Do our best to match the names.
		If there is a match, push the UID to an array.
		*/
		$friends_on_flickr = array();
		if ($loose) {
			
			/*
			Loop through each friend. If their first or last name is empty, skip.
			Otherwise try to match the last name and first initial or the first name
			and last initial.
			*/
			foreach ($flickr_friend_names as $friend) {

				$first_name = strtolower(substr($friend, 0, strpos($friend, ' ')));
				$last_name = strtolower(substr($friend, strpos($friend, ' ')));

				if (strlen(trim($last_name)) == 0 or strlen(trim($first_name)) == 0) {
					continue;
				}
				else if (strlen(trim($last_name)) > 1 or strlen(trim($first_name)) > 1) {

					// Match Last Name, First Initial
					$friend_key = $this->multi_array_search(trim($last_name), $facebook_friend_names);
					if (!empty($friend_key)) {
						$first_initial = strtolower(substr($friend, 0, 1));
						$first_initial_fb = substr($facebook_friend_names[$friend_key[0]]['first_name_lower'], 0, 1);
						if ($first_initial == $first_initial_fb) {
							array_push($friends_on_flickr, $facebook_friend_names[$friend_key[0]]['uid']);
							continue;
						}
					}

					// Match First Name, Last Initial
					$friend_key = $this->multi_array_search(trim($first_name), $facebook_friend_names);
					if (!empty($friend_key)) {
						$last_initial = strtolower(substr($friend, strpos($friend, ' ')+1, 1));
						$last_initial_fb = substr($facebook_friend_names[$friend_key[0]]['last_name_lower'], 0, 1);
						if ($last_initial == $last_initial_fb) {
							array_push($friends_on_flickr, $facebook_friend_names[$friend_key[0]]['uid']);
							continue;
						}
					}

				}
				else {

					// Match Full Name
					$friend_key = $this->multi_array_search($friend, $facebook_friend_names);
					if (!empty($friend_key)) {
						array_push($friends_on_flickr, $facebook_friend_names[$friend_key[0]]['uid']);
						continue;
					}

				}

			}

		}
		else {
			
			/*
			Loop through each friend. If the first or last name is blank, skip.
			If the last name is 1 and the first name is more than 1, match first name, last initial.
			If the last name is more than 1 and the first name is 1, match last name, first initial.
			Otherwise, match full name.
			*/
			foreach ($flickr_friend_names as $friend) {

				$first_name = trim(strtolower(substr($friend, 0, strpos($friend, ' '))));
				$last_name = trim(strtolower(substr($friend, strpos($friend, ' '))));

				if (strlen(trim($last_name)) == 0 or strlen(trim($first_name)) == 0) {
					// Nothing for first or last name, skipping
					continue;
				}
				else if (strlen($last_name) == 1 and strlen($first_name) > 1) {

					// Match First Name, Last Initial
					$friend_key = $this->multi_array_search(trim($first_name), $facebook_friend_names);
					if (!empty($friend_key)) {
						$last_initial = strtolower(substr($friend, strpos($friend, ' ')+1, 1));
						$last_initial_fb = substr($facebook_friend_names[$friend_key[0]]['last_name_lower'], 0, 1);
						if ($last_initial == $last_initial_fb) {
							array_push($friends_on_flickr, $facebook_friend_names[$friend_key[0]]['uid']);
							continue;
						}
					}

				}
				else if (strlen($last_name) > 1 and strlen($first_name) == 1) {

					// Match Last Name, First Initial
					$friend_key = $this->multi_array_search(trim($last_name), $facebook_friend_names);
					if (!empty($friend_key)) {
						$first_initial = strtolower(substr($friend, 0, 1));
						$first_initial_fb = substr($facebook_friend_names[$friend_key[0]]['first_name_lower'], 0, 1);
						if ($first_initial == $first_initial_fb) {
							array_push($friends_on_flickr, $facebook_friend_names[$friend_key[0]]['uid']);
							continue;
						}
					}

				}
				else {

					// Match Full Name
					$friend_key = $this->multi_array_search($friend, $facebook_friend_names);
					if (!empty($friend_key)) {
						array_push($friends_on_flickr, $facebook_friend_names[$friend_key[0]]['uid']);
						continue;
					}

				}

			}

		}
		
		return $friends_on_flickr;
		
	}
	
	/**
	 * Gets a comma-delimited list of friends who are not on Flickr.
	 * 
	 * @author Brad Dougherty <bdougherty@gmail.com>
	 * @return string A comma-delimited list of friends not on Flickr
	 */
	public function get_friends_not_on_flickr($loose = false) {
		
		// Get the list of friends on flickr and all friends
		$friends_on_flickr = $this->find_friends_on_flickr($loose);
		$facebook_friend_names = $this->facebook->api_client->users_getInfo($this->facebook->api_client->friends_get(), array('has_added_app'));
		$friends_not_on_flickr = '';
		
		/*
		Loop through each friend. If the user isn't in the list of Flickr friends,
		add them to the list.
		*/
		foreach ($facebook_friend_names as $friend) {
			$search = array_search($friend['uid'], $friends_on_flickr);
			if ($search === false) {
				if ($friends_not_on_flickr != '') {
					$friends_not_on_flickr .= ',';
				}
				$friends_not_on_flickr .= $friend['uid'];
			}
		}
		return $friends_not_on_flickr;
	}
	
	/**
	 * Gets a comma-delimited list of friends that have the app installed.
	 * 
	 * @author Brad Dougherty <bdougherty@gmail.com>
	 * @return string A comma-delimited list of friends with the app installed
	 */
	public function get_friends_with_app() {
		// Get list of friends who have this app installed
		$fql_result = $this->facebook->api_client->fql_query("SELECT uid FROM user WHERE has_added_app=1 and uid IN (SELECT uid2 FROM friend WHERE uid1 = $this->uid)");
		
		// Build a delimited list of friends with the app installed
		$friends_with_app = '';
		for ($i = 0; $i < count($fql_result); $i++) {
			if ($friends_with_app != "") {
				$friends_with_app .= ",";
			}
			$friends_with_app .= $fql_result[$i]["uid"];
		}
		return $friends_with_app;
	}
	
	/**
	 * Gets the page number from the URL.
	 * 
	 * @author Brad Dougherty <bdougherty@gmail.com>
	 */
	private function get_page() {
		$page = (empty($_GET['p'])) ? 1 : $_GET['p'];
		$this->page = ($page < 1) ? 1 : $page;
	}
	
	/**
	 * Returns a friendly string for the date of the photo.
	 * 
	 * @author Brad Dougherty <bdougherty@gmail.com>
	 * @param array $photo The array returned from photos_getInfo
	 * @return string The friendly list of tags
	 */
	public function get_photo_date($photo) {
		$granularity = $photo['dates']['takengranularity'];
		$date_taken = strtotime($photo['dates']['taken']);
		
		if ($granularity == 6) {
			$date = 'Taken some time in <a href="'.$this->flickr->urls_getUserPhotos($this->nsid).'archives/undated/'.date("Y/", $date_taken).'">'.date("Y", $date_taken).'</a>';
		}
		else if ($granularity == 4) {
			$date = 'Taken in <a href="'.$this->flickr->urls_getUserPhotos($this->nsid).'archives/undated/'.date("Y/m/", $date_taken).'">'.date("F Y", $date_taken).'</a>';
		}
		else {
			$date = 'Taken on <a href="'.$this->flickr->urls_getUserPhotos($this->nsid).'archives/date-taken/'.date("Y/m/d/", $date_taken).'">'.date("F j, Y", $date_taken).'</a>';
		}
		return $date;
	}
	
	/**
	 * Returns a friendly string with the tags from a photo. The string
	 * is comma-delimited and last two tags are separated with 'and'.
	 * 
	 * @author Brad Dougherty <bdougherty@gmail.com>
	 * @param array $photo The array returned from photos_getInfo
	 * @return string The friendly list of tags
	 */
	public function get_tag_string($photo) {
		
		// Get the number of tags
		$tag_count = count($photo['tags']['tag']);
		
		// Create the blank string
		$tags = '';
		
		// If there are tags
		if ($tag_count > 0) {
										
			// Create an array of the tags with links excluding machine tags
			$tag_array = array();
			for ($i = 0; $i < $tag_count; $i++) {
				if (!$photo['tags']['tag'][$i]['machine_tag']) {
					$raw = $photo['tags']['tag'][$i]['raw'];
					$content = $photo['tags']['tag'][$i]['_content'];									
					$s = '<a href="'.$this->flickr->urls_getUserPhotos($this->nsid).'tags/'.urlencode($content).'/">'.$raw.'</a>';
					array_push($tag_array, $s);
				}
			}
										
			// Output the tags in a friendly string
			$tags = 'Tags: '.$this->implode_proper($tag_array);
			
		}
		
		// Return the string
		return $tags;
		
	}
	
	/**
	 * Gets the tagged photos of a user.
	 * 
	 * @author Brad Dougherty <bdougherty@gmail.com>
	 * @param int $uid The user ID
	 * @return array The photos array
	 */
	public function get_tagged_photos_of($uid, $uid2 = null) {
		return $this->flickr->photos_search(array(
			'privacy_filter' => $this->privacy_filter['public'],
			'per_page'       => $this->photos_per_page,
			'page'           => $this->page,
			'extras'         => 'date_upload',
			'machine_tags'   => 'fb:user='.$uid,
		));
	}
	
	/**
	 * Gets the UIDs of users tagged in the Flickr photo.
	 * 
	 * @author Brad Dougherty <bdougherty@gmail.com>
	 * @param array $photo The flickr photo
	 * @return array An array of the tagged uids
	 */
	public function get_tagged_users($photo) {
		$tagged_users = array();
		foreach ($photo['tags']['tag'] as $tag) {
			if ($tag['machine_tag'] and strpos($tag['_content'], 'fb:user=') !== false) {
				array_push($tagged_users, substr($tag['_content'], 8));
			}
		}
		return $tagged_users;
	}
	
	/**
	 * Checks to see if the user is friends with the viewer of the page.
	 * 
	 * @author Brad Dougherty <bdougherty@gmail.com>
	 * @return boolean True if they are friends
	 * @deprecated Use add_to_fbml() to add the proper FBML tags instead of this method.
	 */
	public function is_friends_with_viewer() {
		// Get the viewer
		$viewer = $this->facebook->get_loggedin_user();
		
		// Only check if the viewer and user are different
		$are_friends = true;
		if ($viewer != $this->uid) {
			$are_friends = $this->facebook->api_client->friends_areFriends($this->uid, $viewer);
			$are_friends = $are_friends[0]['are_friends'];
		}
		
		return ($are_friends) ? true : false;
	}
	
	/**
	 * Displays a Facebook-style pager. Currently it uses a custom pager,
	 * hopefully Facebook will eventually provide a standard pager. First
	 * and last links are displayed when the respective page is not displayed
	 * as part of the numbered pages.
	 * 
	 * @author Brad Dougherty <bdougherty@gmail.com>
	 * @param int $page_count The number of pages
	 * @param int $num_to_show The maximum number of pages to show at a time (defaults to 5)
	 * @param boolean $first_last Whether to display links to the first and last pages when applicable
	 */
	public function pager($page_count, $num_to_show = 5, $first_last = true) {
		
		// Only show the pager if there is more than one page		
		if ($page_count > 1) {
						
			// URL is that of the calling page
			$uri = explode($this->app_call_url, $_SERVER['SCRIPT_URI']);
			if (!empty($_GET['p'])) {
				$url = $this->app_url.substr($uri[1], 0, strpos($uri[1], 'page'));
			}
			else {
				$url = $this->app_url.$uri[1];
			}
			
			// Make sure we aren't trying to show more pages than there are
			if ($num_to_show > $page_count) {
				$num_to_show = $page_count;
			}
			
			/*
			Figure out the first page we need to show then get the last from that.
			
			Then make sure that the start is at least 1, and that the end is no
			more than the total number of pages. The while statements will keep
			the difference between $start and $end to $num_to_show.
			*/
			$start = $this->page - floor($num_to_show / 2);
			$end = $start + ($num_to_show - 1);
			while ($start < 1) {
				$start++;
				$end++;
			}
			while ($end > $page_count) {
				$end--;
				$start--;
			}
			
			// Open the pagerpro list
			echo '<ul class="pagerpro">';

			// Show the first page link when applicable
			if (($start > 1) and $first_last and ($page_count > $num_to_show)) {
				echo '<li><a href="'.$url.'page/1/">First</a></li>';
			}
			
			// Show next when applicable
			if ($this->page > 1) {
				echo '<li><a href="'.$url.'page/'.($this->page - 1).'/">Prev</a></li>';
			}
			
			// Show the pages
			for ($i = $start; $i <= $end; $i++) {
				echo '<li';
				if ($this->page == $i) {
					echo ' class="current"';
				}
				echo '><a href="'.$url.'page/'.$i.'/">'.$i.'</a></li>';
			}
			
			// Show previous when applicable
			if ($this->page < $page_count) {
				echo '<li><a href="'.$url.'page/'.($this->page + 1).'/">Next</a></li>';
			}
			
			// Show the last page link when applicable
			if (($end < $page_count) and $first_last and ($page_count > $num_to_show)) {
				echo '<li><a href="'.$url.'page/'.$page_count.'/">Last</a></li>';
			}
			
			// Close the list
			echo '</ul>';
			
		}
		
	}
	
	/**
	 * Prints out the comments for a photo or photoset. Attempts
	 * to match a Flickr user to their Facebook user.
	 * 
	 * @author Brad Dougherty <bdougherty@gmail.com>
	 * @param array $comments The array returned by any of the _comments_getList functions
	 */
	public function print_comments($comments) {
		
		// If there are comments, loop through
		if (count($comments['comment']) > 0) {
			
			foreach ($comments['comment'] as $comment) {
				
				echo '
					<table id="comments_'.$comment['id'].'>" class="wallpost" border="0" cellspacing="0" width="100%">
						<tr>
							<td class="wallimage"><span><img src="http://flickr.com/buddyicons/'.$comment['author'].'.jpg" alt="" /></span></td>

							<td class="wallinfo">
								<div class="wallheader">
									<a href="'.$this->flickr->urls_getUserPhotos($comment['author']).'">'.$comment['authorname'].'</a>
				';
				$comment_uid = $this->get_uid($comment['author']);
				if (!empty($comment_uid)) {
					echo ' (<fb:userlink uid="'.$comment_uid.'" ifcantsee="" />)';
				}
				echo '
									<br />
									<small>on '.date('M j, Y', $comment['datecreate']).'</small>
								</div>

								<div class="walltext">
									'.$comment['_content'].'
								</div>

								<div class="wallactions"></div>
							</td>
						</tr>
					</table>
				';
				
			}
			
		}
		
	}
	
	/**
	 * Prints out the media header common to canvas pages that display photos.
	 * 
	 * @author Brad Dougherty <bdougherty@gmail.com>
	 * @param string $extra_text The extra text to put after _'s Flickr Photos
	 */
	public function print_media_header($extra_text = '') {
		echo '
			<div class="media_header clearfix">
				<div class="picture">
					<img src="http://flickr.com/buddyicons/'.$this->nsid.'.jpg" />
				</div>
				<div class="user_info">
					<div class="media_gray_bg clearfix">
						<h2>'.$this->get_name(true).' 
							<span style="color:#3e79c0;">Flick<span style="color:#d760a9;">r</span></span> Photos';
		echo (empty($extra_text)) ? '' : '<span> - '.$extra_text.'</span>';
		echo '
						</h2>
					</div>
					<div class="media_actions clearfix">

						<fb:if-can-see uid="'.$this->uid.'" what="profile">
							<a href="http://facebook.com/profile.php?id='.$this->uid.'">Back to Profile</a>
							<span class="pipe">|</span>
						</fb:if-can-see>

						<a href="'.$this->flickr->urls_getUserProfile($this->nsid).'">'.$this->get_name().' Flickr Profile</a>

						<span class="pipe">|</span>

						<a href="'.$this->flickr->urls_getUserPhotos($this->nsid).'">'.$this->get_name().' Flickr Photostream</a>

						<fb:user uid="'.$this->uid.'">
							<fb:else>
								<span class="pipe">|</span>
								<a href="http://facebook.com/inbox/?compose&amp;id='.$this->uid.'">Send <fb:pronoun uid="'.$this->uid.'" objective="true" /> a Message</a>
							</fb:else>
						</fb:user>

					</div>
				</div>
			</div>
		';
	}
	
	// Temporary to hold tagging notification
	private function send_tagging_notification($tagger, $taggee, $pid) {
		$this->facebook->api_client->feed_publishTemplatizedAction(
			$tagger,
			'{target} tagged {actor} in a <a href="http://rit.facebook.com/apps/application.php?api_key='.FACEBOOK_API_KEY.'">Flickr {photo}</a>.',
			'',
			'<b><a href="{url}">{title}</a></b>',
			'{"url":"'.$url.'","title":"'.$photo['title'].'"}',
			$description,
			$images[0]['src'],
			$images[0]['link'],
			$images[1]['src'],
			$images[1]['link'],
			$images[2]['src'],
			$images[2]['link'],
			$images[3]['src'],
			$images[3]['link'],
			$taggee
		);
	}
	
}

?>